Repository navigation
Conversation
Python truthiness treats any non-empty string — including "false" — as
truthy, so the check `not claims.get("email_verified")` accepted forged
ID tokens whose email_verified claim was a string. An attacker could
bypass the allowlist by supplying a token where email_verified
serializes to "false" instead of the boolean false.
Replace `not claims.get("email_verified")` with
`claims.get("email_verified") is not True` so only the real boolean
True satisfies the check. Add regression tests covering the string
bypass, a missing claim, and an explicit null.
Fixes google#7289
8 of 9 tasks
Collaborator
|
thanks @mdabydeen for the fix. the same change landed in 4434070 (#7295), so GoogleOidcVerifier now only accepts a boolean true email_verified. it's on main but not in a release yet. please open a new issue if this is still happening. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
GoogleOidcVerifier.__call__checksnot claims.get("email_verified")— a Python truthiness check. Any non-empty string is truthy in
Python, so an attacker could bypass the allowlist by supplying a
forged ID token whose
email_verifiedclaim serializes to thestring
"false"instead of the booleanFalse.Solution
Replace
not claims.get("email_verified")withclaims.get("email_verified") is not Trueso only the realbool(True)satisfies the check. No other claim type cantrick the verifier.
Closes: #7289
Testing Plan
Unit Tests
All 81 tests pass, including 10 new regression tests:
Test class
TestEmailVerifiedStrictBooleancovers:test_rejects_string_false_email_verified"false"test_rejects_string_true_email_verified"true"test_rejects_missing_email_verified_claimtest_rejects_null_email_verifiedNonetest_accepts_boolean_true_email_verifiedTrueManual verification
The regression test
test_rejects_string_false_email_verifiedfails on
mainand passes on this branch:Checklist